package com.tanhua.dubbo.api.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.BlacklistApi;
import com.tanhua.dubbo.mapper.BlacklistMapper;
import com.tanhua.dubbo.pojo.BlackList;
import com.tanhua.dubbo.vo.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService(version = "1.0.0")
public class BlacklistApiImpl implements BlacklistApi {

    @Autowired
    private BlacklistMapper blacklistMapper;
    @Override
    public PageInfo queryBlacklist(Integer page, Integer pageSize, Long userId) {
        PageInfo<BlackList> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page);
        pageInfo.setPageSize(pageSize);

        List<BlackList> blackList = this.blacklistMapper.selectList(new QueryWrapper<BlackList>().eq("user_id", userId).orderByDesc("updated"));
        pageInfo.setRecords(blackList);

        return pageInfo;
    }

    @Override
    public Boolean deleteBlackList(Long uid,Long userId) {
            //查询当前用户是否存在
        QueryWrapper<BlackList> eq = new QueryWrapper<BlackList>().eq("user_id", userId).eq("black_user_id", uid);
        BlackList blackList = this.blacklistMapper.selectOne(eq);
        if(ObjectUtil.isNotEmpty(blackList)){
       return this.blacklistMapper.delete(eq)==1;
        }
        return false;
    }
}
